package com.sweet.imserver;

import com.sweet.imserver.dao.DaoVerticle;
import com.sweet.imserver.server.HttpServerVerticle;
import com.sweet.imserver.server.IMServerVerticle;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
import io.vertx.core.impl.logging.Logger;
import io.vertx.core.impl.logging.LoggerFactory;

import java.util.concurrent.TimeUnit;

public class MainVerticle extends AbstractVerticle {

  public static void main(String[] args) {
    Vertx.vertx(new VertxOptions()
      .setBlockedThreadCheckIntervalUnit(TimeUnit.DAYS)
      .setBlockedThreadCheckInterval(2))
      .deployVerticle(new MainVerticle());
  }

  private static final Logger logger = LoggerFactory.getLogger(MainVerticle.class);

  @Override
  public void start() throws Exception {
    vertx.deployVerticle(new DaoVerticle())
      .compose(f -> vertx.deployVerticle(new IMServerVerticle()))
      .compose(f -> vertx.deployVerticle(new HttpServerVerticle()))
      .onComplete(res -> {
        if (res.succeeded()) {
          logger.debug("服务全部启动成功");
        } else {
          res.cause().printStackTrace();
          logger.error("服务启动失败", res.cause());
        }
      });
  }
}
